<template>
  <div class="slideshow">
    <van-swipe :autoplay="3000" indicator-color="#ff0000">
      <van-swipe-item v-for="(item, index) in imageList" :key="index">
        <img :src="item.image" @load="slideshowLoad" alt=""/>
      </van-swipe-item>
    </van-swipe>
  </div>
</template>

<script>
  export default {
    name: "Slideshow",
    props: {
      imageList: {
        type: Array,
        default() {
          return [];
        }
      }
    },
    data() {
      return {
        isLoading: true,
      }
    },
    methods: {
      slideshowLoad() {
        //一张图片加载完成就可以获取位置
        if (this.isLoading) {
          this.$emit("slideshowLoad");
          this.$bus.$emit("imgLoaded");
          this.isLoading = false;
        }
      }
    }
  }
</script>

<style scoped>
  .slideshow {
    width: 100%;
  }
  .slideshow img {
    width: 100%;
    vertical-align: middle;
  }
  .slideshow /deep/ .van-swipe__indicator {
    width: 10px;
    height: 10px;
    border-radius: 100%;
    opacity: 0.8;
    background-color: white;
  }
</style>
